import { _decorator, Component, ParticleSystem } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('DestroyAfterParticle')
export class DestroyAfterParticle extends Component {
    start() {
        const particleSystem = this.node.getComponent(ParticleSystem);
        
        if (particleSystem) {
            // 计算粒子总持续时间（考虑循环情况）
            const duration = particleSystem.duration * (particleSystem.loop ? 100 : 1);
            
            // 设置定时器在播放结束后销毁
            this.scheduleOnce(() => {
                this.node.destroy();
            }, duration);
        }
    }
}